
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <title>承保利润测算工具</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    body { font-family: Arial, sans-serif; padding: 16px; max-width: 600px; margin: auto; }
    h2 { color: #0070f3; }
    input { width: 100%; padding: 6px; margin: 6px 0; }
    p { margin: 6px 0; }
  </style>
</head>
<body>
  <h2>承保利润测算工具</h2>
  <label>总保费收入（万元）<input type="number" id="premium" value="100"></label>
  <label>预计赔付率（%）<input type="number" id="lossRatio" value="60"></label>
  <label>合约分出比例（%）<input type="number" id="treatyShare" value="50"></label>
  <label>临分分出保费（万元）<input type="number" id="facOutPremium" value="10"></label>
  <label>临分手续费率（%）<input type="number" id="facCommissionRate" value="15"></label>
  <label>前端手续费率（%）<input type="number" id="frontendCommissionRate" value="15"></label>
  <label>其他运营费用（万元）<input type="number" id="operatingCost" value="5"></label>
  <button onclick="calculate()">点击计算</button>

  <div id="result" style="margin-top: 20px;"></div>

  <script>
    function getSlidingCommissionRate(lr) {
      if (lr <= 43) return 38.3;
      if (lr > 81) return 9.3;
      return 38.3 - (lr - 43) * 0.75;
    }

    function calculate() {
      const p = (id) => parseFloat(document.getElementById(id).value) || 0;
      const premium = p("premium");
      const lossRatio = p("lossRatio");
      const treatyShare = p("treatyShare");
      const facOut = p("facOutPremium");
      const facFee = p("facCommissionRate");
      const frontendFee = p("frontendCommissionRate");
      const opCost = p("operatingCost");

      const treatyOut = (premium * treatyShare) / 100;
      const treatyClaim = (treatyOut * lossRatio) / 100;
      const treatyLossRatio = treatyOut ? (treatyClaim / treatyOut) * 100 : 0;
      const treatyFeeRate = getSlidingCommissionRate(treatyLossRatio);
      const treatyFee = (treatyOut * treatyFeeRate) / 100;

      const facClaim = (facOut * lossRatio) / 100;
      const facCommission = (facOut * facFee) / 100;

      const retainedPremium = premium - treatyOut - facOut;
      const totalClaim = (premium * lossRatio) / 100;
      const retainedClaim = totalClaim - treatyClaim - facClaim;
      const frontendCost = (premium * frontendFee) / 100;

      const profit = retainedPremium - retainedClaim - frontendCost - opCost + treatyFee + facCommission;
      const ratio = premium ? (profit / premium) * 100 : 0;

      document.getElementById("result").innerHTML = `
        <p><b>合约赔付金额：</b>${treatyClaim.toFixed(2)} 万元</p>
        <p><b>合约赔付率：</b>${treatyLossRatio.toFixed(2)}%</p>
        <p><b>合约浮动手续费率：</b>${treatyFeeRate.toFixed(2)}%</p>
        <p><b>合约手续费收入：</b>${treatyFee.toFixed(2)} 万元</p>
        <p><b>临分赔付金额：</b>${facClaim.toFixed(2)} 万元</p>
        <p><b>临分手续费收入：</b>${facCommission.toFixed(2)} 万元</p>
        <p><b>自留赔付金额：</b>${retainedClaim.toFixed(2)} 万元</p>
        <p><b>承保利润：</b>${profit.toFixed(2)} 万元</p>
        <p><b>承保利润率：</b>${ratio.toFixed(2)}%</p>
      `;
    }
  </script>
</body>
</html>
